<template>
  <el-card class="box-card">
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="值班医生">
        <template>
          <el-select v-model="form.docId" placeholder="请选择">
            <el-option
                    v-for="item in doctors"
                    :key="item.docId"
                    :label="item.realName"
                    :value="item.docId">
            </el-option>
          </el-select>
        </template>
      </el-form-item>
      <el-form-item label="值班日期">
        <el-date-picker
                v-model="form.dutyday"
                value-format="yyyy-MM-dd HH:mm:ss"
                :picker-options="{
                        format: 'yyyy-MM-dd HH:mm:ss'
                      }"
                placeholder="值班日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit">立即创建</el-button>
        <el-button @click="cancel">取消</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script>

  import {findAll, add} from '../../network/duty'
  import { findDoctor } from '@/network/doctor'

  export default {
    name: 'DutyAdd',
    created() {
      this.findDoctor()
    },
    methods: {
      onSubmit() {
        console.log(this.form)
        add(this.form).then(res => {
          this.$router.back(1)
        })
      },
      cancel() {
        this.$router.back(1)
      },
      findDoctor() {
        findDoctor().then(res => {
          console.log(res.data.data.records)
          this.doctors = res.data.data.records
        })
      },
    },
    data() {
      return {
        form: {},
        doctors: []
      }
    }
  }
</script>

<style scoped>

</style>
